package top.gxw.routelearn.routeservice

import android.content.Context
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.facade.service.SerializationService
import com.alibaba.fastjson.JSON
import java.lang.reflect.Type

/**
 * author:gxw60
 * date:2021/1/7
 * project:RouteLearn
 * Description:
 *
 *
 * 如果需要传递自定义对象，新建一个类（并非自定义对象类），然后实现 SerializationService,并使用@Route注解标注(方便用户自行选择序列化方式)
 */
@Route(path = "/yourservicegroupname/json")
open class JsonServiceImpl : SerializationService {
    override fun init(context: Context) {}
    override fun <T> json2Object(text: String, clazz: Class<T>): T {
        return JSON.parseObject(text, clazz)
    }

    override fun object2Json(instance: Any): String {
        return JSON.toJSONString(instance)
    }

    override fun <T> parseObject(input: String, clazz: Type): T {
        return JSON.parseObject(input, clazz)
    }
}